package com.homwee.factory;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;

public class FactoryEepromDialog extends Dialog implements OnClickListener {
	private Context mContext;
	private FactoryActivity factoryActivity;
	private RelativeLayout mainLayout;
//	private MenuDataContainer  mDataContainer;
	public FactoryEepromDialog(Context context) {
    	super(context, R.style.Theme_FactorySettingDialog);
    	mContext= context;
    	Log.v("111","");
    	if (context instanceof Activity) {
			factoryActivity = (FactoryActivity)context;
		}
	}

	public FactoryEepromDialog(Context context, AttributeSet attrs) {
		super(context, R.style.Theme_FactorySettingDialog);
		mContext = context;
		if (context instanceof Activity) {
			factoryActivity = (FactoryActivity)context;
		}
	
	}


	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        mDataContainer = MenuDataContainer.getInstance(mContext);
        setContentView(R.layout.factory_eeprom_dialog);
        initView();
       
    }
	public void  initView(){
		Button okButton = (Button)findViewById(R.id.factoryEepromOkButton);
		Button cancelButton = (Button)findViewById(R.id.factoryEepromCancelButton); 
		cancelButton.setOnClickListener(this);
		okButton.setOnClickListener(this);
	}
	
	 public void onClick(View view) {
	        switch (view.getId()) {
	             case R.id.factoryEepromOkButton:
	                 
	            	   final FactoryToast toast = new FactoryToast(factoryActivity);
			    	   toast.setDuration(30);
			    	   toast.setToastIcon(R.drawable.pic_eye);
			    	   toast.setMessage(factoryActivity.getString(R.string.factory_system_reset));
			    	   toast.getTextView().getBackground().setAlpha(200);
//			    	   factoryActivity.getMainLayout().setVisibility(View.INVISIBLE);
			    	   toast.show();
			    	   dismiss();
			    	   Handler mHandler;
					   mHandler = new Handler();
					   mHandler.post(new Runnable() {
					   public void run() {
					   Timer timer = new Timer();
					   TimerTask task = new TimerTask() {
							public void run() {
//					           MenuConfigManager mConfigManager = MenuConfigManager.getInstance(mContext);	
//					           mConfigManager.setNum(MenuConfigManager.FACTORY_EEPROM_INIT,1);
//					           mDataContainer.clearAllData();
							}
					    }; 
					    timer.schedule(task, 200);
							}
						  }); 
	                   break;
	            case R.id.factoryEepromCancelButton:
	                  cancel();
//	                  factoryActivity.getMainLayout().setVisibility(View.VISIBLE);
//	                  factoryActivity.getListView().requestFocus();
//	                  factoryActivity.getListView().setSelection(5);
	                  break;
	        }
	    }

}

